package com.shujia.eight;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo {

    @Test
    public void test2() throws Exception {
//        Date date = new Date(1630053959000L);
        Date date = new Date();
        System.out.println(date);

//        SimpleDateFormat sdf = new SimpleDateFormat();// 默认格式21-8-27 下午4:45
        // yyyy年MM月dd日
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // date -> string
        String format = sdf.format(date);
        System.out.println(format);
        // string -> date
        // 2008-08-08 08:59:59
        String str = "2008-08-08 08:59:59";
        Date parse = sdf.parse(str);
        System.out.println(parse);

    }

    @Test
    public void test1() {
        long timeMillis = System.currentTimeMillis();
        Date date = new Date();
        System.out.println(date);
        System.out.println(date.getTime());
        System.out.println(timeMillis);

        // 创建指定的时间
        date = new Date(1630053959000L);
        System.out.println(date);
    }
}
